package com.jf.anmocker.plugin.asmfactory

import org.gradle.api.Project

open class AnMocker {

    var className: List<String>? = null
    var packages: List<String>? = ArrayList()
    var superClasses: List<String>? = ArrayList()
    var classAnnotations: List<String>? = ArrayList()
    var interfaces: List<String>? = ArrayList()

    // 将获取扩展对象的代码封装为静态方法
    companion object {

        fun getConfig(project: Project): AnMocker {
            // 从 ExtensionContainer 容器获取扩展对象
            var extension: AnMocker? = project.extensions.findByType(
                AnMocker::class.java
            )
            // 配置缺省的时候，赋予默认值
            if (null == extension) {
                extension = AnMocker()
            }
            return extension
        }

        fun readConfig(project: Project, target: AnMockerParams) {
            // 从 ExtensionContainer 容器获取扩展对象
            val extension: AnMocker? = project.extensions.findByType(
                AnMocker::class.java
            )
            // 配置缺省的时候，赋予默认值，AnMockerParams不能为空，否则编译会报错
            target.packages = extension?.packages ?: ArrayList()
            //println("target.packages:${target.packages}")
            target.className = extension?.className ?: ArrayList()
            //println("target.className:${target.className}")
            target.interfaces = extension?.interfaces ?: ArrayList()
            //println("target.interfaces:${target.interfaces}")
            target.superClasses = extension?.superClasses ?: ArrayList()
            //println("target.superClasses:${target.superClasses}")
            target.classAnnotations = extension?.classAnnotations ?: ArrayList()
            //println("target.classAnnotations:${target.classAnnotations}")
        }

    }

}